/**
 * @file       PageInfo_test.cpp
 * @brief      TODO
 * @author     Huabo Zheng
 * @date       Jan 31, 2012
 * @Copyright  2012, www.netgear.com Inc. All rights reserved.
 */

#include "PageInfo.h"
#include "gtest/gtest.h"
namespace NS_LCD_AFW
{
class CPageInfo_test : public ::testing::Test
{
public:
	virtual ~CPageInfo_test()
	{
	}
public:
	virtual void SetUp()
	{
		for (int i = 0; i < 3; ++i)
		{
			m_pi.setPageInfo(i + 1,i * 10,(i + 1) * 10);
		}
		m_pi.setTotalPage(3);
	}
	virtual void TearDown()
	{
	}
	CPageInfo m_pi;
};
TEST_F(CPageInfo_test,test_defualtConstruction)
{
	CPageInfo pi;
	EXPECT_EQ(0,pi.getHightLightObjIndex());
	EXPECT_EQ(1,pi.getTotalPage());
	EXPECT_EQ(1,pi.getCurPage());
	EXPECT_EQ(CPageInfo::UNKNOW,pi.getDirection());
	EXPECT_TRUE(pi.isNeedSwitchPage());
	//EXPECT_FALSE(pi.isNeedUpdateView());)
}
TEST_F(CPageInfo_test,test_getCurPage)
{
	CPageInfo pi;
	pi.setCurPage(1);
	EXPECT_EQ(1,pi.getCurPage());
}
TEST_F(CPageInfo_test,test_setCurPage)
{
	CPageInfo pi;
	pi.setCurPage(1);
	pi.setTotalPage(2);
	EXPECT_EQ(1,pi.getCurPage());

	pi.setCurPage(0);
	EXPECT_EQ(1,pi.getCurPage());

	pi.setCurPage(2);
	EXPECT_EQ(2,pi.getCurPage());

	pi.setCurPage(3);
	EXPECT_EQ(2, pi.getCurPage());

}
TEST_F(CPageInfo_test,test_getStartIndex)
{
	m_pi.setCurPage(1);
	EXPECT_EQ(0, m_pi.getStartIndex());

	m_pi.setCurPage(2);
	EXPECT_EQ(10, m_pi.getStartIndex());

	m_pi.setTotalPage(10);
	m_pi.setCurPage(10);
	EXPECT_EQ(0, m_pi.getStartIndex());

	m_pi.setTotalPage(3);
	m_pi.setCurPage(3);
	EXPECT_EQ(20, m_pi.getStartIndex());

}
TEST_F(CPageInfo_test,test_getEndIndex)
{
	m_pi.setCurPage(1);
	EXPECT_EQ(10, m_pi.getEndIndex());

	m_pi.setCurPage(2);
	EXPECT_EQ(20, m_pi.getEndIndex());

	m_pi.setTotalPage(10);
	m_pi.setCurPage(10);
	EXPECT_EQ(0, m_pi.getEndIndex());

	m_pi.setTotalPage(3);
	m_pi.setCurPage(3);
	EXPECT_EQ(30, m_pi.getEndIndex());

}
TEST_F(CPageInfo_test,test_setHightLightObjIndex)
{
	m_pi.setCurPage(1);
	EXPECT_EQ(1,m_pi.getCurPage());
	EXPECT_EQ(0,m_pi.getStartIndex());
	EXPECT_EQ(10,m_pi.getEndIndex());

	m_pi.setHightLightObjIndex(-1);
	EXPECT_EQ(0,m_pi.getHightLightObjIndex());

	m_pi.setHightLightObjIndex(0);
	EXPECT_EQ(0,m_pi.getHightLightObjIndex());

	m_pi.setHightLightObjIndex(1);
	EXPECT_EQ(1,m_pi.getHightLightObjIndex());

	m_pi.setHightLightObjIndex(9);
	EXPECT_EQ(9,m_pi.getHightLightObjIndex());

	m_pi.setHightLightObjIndex(10);
	EXPECT_EQ(9,m_pi.getHightLightObjIndex());

	m_pi.setCurPage(2);
	EXPECT_EQ(2,m_pi.getCurPage());
	EXPECT_EQ(10,m_pi.getStartIndex());
	EXPECT_EQ(20,m_pi.getEndIndex());

	m_pi.setHightLightObjIndex(9);
	EXPECT_EQ(10,m_pi.getHightLightObjIndex());

	m_pi.setHightLightObjIndex(10);
	EXPECT_EQ(10,m_pi.getHightLightObjIndex());

	m_pi.setHightLightObjIndex(21);
	EXPECT_EQ(19,m_pi.getHightLightObjIndex());
}
TEST_F(CPageInfo_test,test_getHightLightObjIndex)
{
	m_pi.setCurPage(1);
	EXPECT_EQ(1, m_pi.getCurPage());
	EXPECT_EQ(0, m_pi.getStartIndex());
	EXPECT_EQ(10, m_pi.getEndIndex());

	m_pi.setHightLightObjIndex(5);
	EXPECT_EQ(5,m_pi.getHightLightObjIndex());
}
TEST_F(CPageInfo_test,test_getTotalPage)
{
	EXPECT_EQ(3,m_pi.getTotalPage());
}
TEST_F(CPageInfo_test,test_isNeedSwitchPage)
{
	m_pi.setNeedSwitchPage(true);
	EXPECT_TRUE(m_pi.isNeedSwitchPage());

	m_pi.setNeedSwitchPage(false);
	EXPECT_FALSE(m_pi.isNeedSwitchPage());
}
TEST_F(CPageInfo_test,test_setNeedSwitchPage)
{
	m_pi.setNeedSwitchPage(true);
	EXPECT_TRUE(m_pi.isNeedSwitchPage());

	m_pi.setNeedSwitchPage(false);
	EXPECT_FALSE(m_pi.isNeedSwitchPage());
}
TEST_F(CPageInfo_test,test_setTotalPage)
{
	CPageInfo pi;
	pi.setTotalPage(100);
	EXPECT_EQ(100,pi.getTotalPage());

}
TEST_F(CPageInfo_test,test_setDirection)
{
	m_pi.setDirection(CPageInfo::UP);
	EXPECT_EQ(CPageInfo::UP,m_pi.getDirection());
}
TEST_F(CPageInfo_test,test_getDirection)
{
	m_pi.setDirection(CPageInfo::UP);
	EXPECT_EQ(CPageInfo::UP,m_pi.getDirection());
}
TEST_F(CPageInfo_test,test_setPageInfo)
{
	CPageInfo pi;
	pi.setTotalPage(2);
	pi.setCurPage(1);
	pi.setPageInfo(1, 0, 5);

	EXPECT_EQ(2, pi.getTotalPage());
	EXPECT_EQ(1, pi.getCurPage());
	EXPECT_EQ(0, pi.getStartIndex());
	EXPECT_EQ(5, pi.getEndIndex());

	pi.setPageInfo(1, 10, 5);
	EXPECT_EQ(10, pi.getStartIndex());
	EXPECT_EQ(11, pi.getEndIndex());

	pi.setPageInfo(1, 5, 5);
	EXPECT_EQ(5, pi.getStartIndex());
	EXPECT_EQ(6, pi.getEndIndex());

}
} /* namespace NS_LCD_AFW */
